package czk.jvm.lecture.bytecode;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理对象
 */
public class DynamicSubject implements InvocationHandler {
    //将真实对象传入
    private Subject subject;
    public DynamicSubject(){}
    public DynamicSubject(Subject subject){
        this.subject=subject;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //代理前
        System.out.println("代理前"+"  "+method);
        method.invoke(subject,args);
        System.out.println("代理后"+"  "+method);
        return proxy;
    }
}
